// *************************************************************************************************
//
// MK3D Engine
// --------------------------------------
// Copyright (C) 2007-2011 Zeb (mailto: zebbey@gmail.com)
//
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// *************************************************************************************************
#ifndef __H_MK_FRAME_INTERPOLATOR__
#define __H_MK_FRAME_INTERPOLATOR__

namespace MK3DE
{
	enum INTERPOLATE_CYCLE
	{
		IC_ONCE,
		IC_LOOP,
	};

	class MK3DE_API CFrameInterpolator
	{
	public:
		CFrameInterpolator() : _start(0), _end(0), _current(0), _interval(0), _cycle(IC_LOOP) {}
		~CFrameInterpolator() {}

		void SetParam(float start, float end, float interval, INTERPOLATE_CYCLE cycle)
		{
			_start = start;
			_end = end;
			_interval = interval;
			_cycle = cycle;
		}

		void SetInterval(float interval)
		{
			_interval = interval;
		}

		float GetInterval() { return _interval; }

		void Update(DWORD dt)
		{
			if (abs(_start - _end) < MK_EPSILON)
				return;

			float df = (float)dt / _interval;
			_current += df;
			if (_current >= _end)
			{
				if (_cycle == IC_LOOP)
				{
					float length = _end - _start;
					while (_current >= _end)
						_current -= length;
				}
				else
					_current = _end - 1;
			}
		}

		float GetCurrent() { return _current; }
		void SetCurrent(float current) { _current = current; }

	protected:
		float _start;
		float _end;
		float _current;

		float _interval;
		INTERPOLATE_CYCLE _cycle;
	};
}
#endif // __H_MK_FRAME_INTERPOLATOR__